// ==UserScript==
// @name         GitHub Release 界面添加代理下载链接
// @namespace    http://tampermonkey.net/
// @version      0.0.2-2025-01-21
// @description  为GitHub Release 界面的附件添加使用代理服务器下载的链接，代理服务器可能会经常变动，使用 localStorage.setItem("github_proxy_host","域名") 可以自己设置域名（不带https)
// @match        https://github.com/*/*/releases/**
// @match        https://github.com/*/*/releases
// @icon         https://ghproxy.link/favicon.ico
// @grant        none
// @author       AgMonk
// @homepage     https://gitee.com/AgMonk/tampermonkey-script
// @downloadURL https://gitee.com/AgMonk/tampermonkey-script/raw/master/github/github-release-proxy.user.js
// @updateURL https://gitee.com/AgMonk/tampermonkey-script/raw/master/github/github-release-proxy.user.js
// ==/UserScript==

(function () {
    'use strict';
    const flag = "ghph"
    const hostKey = "github_proxy_host"
    const defaultHost = "ghfast.top"

    setInterval(() => {
        let host = localStorage.getItem(hostKey) || defaultHost;
        // 下载链接
        const links = [...document.getElementsByClassName('Truncate')]
        links.forEach(item=>{
            // 如果标签没标记则继续执行
            if (!item[flag]){
                item[flag] = true
                // 代理链接
                const proxyLink = document.createElement('a');
                proxyLink.href = new URL(`github.com${item.attributes['href'].value}`,`https://${defaultHost}`).toString();
                proxyLink.innerText = "代理下载"
                proxyLink.className = "Truncate-text text-bold"
                console.log(proxyLink.href)
                item.insertAdjacentElement('afterend', proxyLink)
            }
        })

    }, 1000)
})();
